home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / CLFNAME.CPP < prev    next >
C/C++ Source or Header  |  1993-09-02  |  11KB  |  362 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    clfname.cpp
  5. //   Title:    C++ Class Libraries
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains code for the class CL_FNAME.
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <class.hpp>
  41.  
  42.  
  43. //----------------------------------------------------------------------------
  44. //   Description:    Default constructor
  45. //    Parameters:
  46. //       Returns:    
  47. //----------------------------------------------------------------------------
  48. FN_M CL_FNAME::CL_FNAME() :  CL_STRING(MAX_PATH+1)
  49. {
  50.     CL_FNAME::Initialize(CL_INIT_CLASS);
  51. }
  52.  
  53. //----------------------------------------------------------------------------
  54. //   Description:    Default constructor
  55. //    Parameters:
  56. //       Returns:
  57. //----------------------------------------------------------------------------
  58. FN_MV CL_FNAME::CL_FNAME(PCSZ pcsz, ...) : CL_STRING(MAX_PATH+1)
  59. {
  60.     CL_FNAME::Initialize(CL_INIT_CLASS);
  61.     va_list marker;
  62.     va_start(marker, pcsz);
  63.     CL_STRING::Create(MAX_PATH+1, pcsz, marker);
  64.     va_end(marker);
  65. }
  66.  
  67.  
  68. //----------------------------------------------------------------------------
  69. //   Description:    Copy constructor
  70. //    Parameters:    rccl_fname        Reference to object to copy.
  71. //       Returns:    
  72. //----------------------------------------------------------------------------
  73. FN_M CL_FNAME::CL_FNAME(RCCL_FNAME rccl_fname)
  74. {
  75.     CL_FNAME::Initialize(CL_INIT_CLASS);
  76.     *this = rccl_fname;
  77. }
  78.  
  79.  
  80. //----------------------------------------------------------------------------
  81. //   Description:    Destructor
  82. //    Parameters:
  83. //       Returns:    
  84. //----------------------------------------------------------------------------
  85. FN_M CL_FNAME::~CL_FNAME()
  86. {
  87.     CL_FNAME::Destroy(FALSE);
  88. }
  89.  
  90.  
  91. //----------------------------------------------------------------------------
  92. //   Description:    Destroy object. Free any resources used by object.
  93. //                          Normally called by destructor.
  94. //                        Should allow multiple calls from various classes.
  95. //    Parameters:    fDestroyAll        Destroy parents also?
  96. //                                            Default is TRUE.
  97. //       Returns:    TRUE if successful.
  98. //----------------------------------------------------------------------------
  99. BOOL FN_M CL_FNAME::Destroy(BOOL fDestroyAll)
  100. {
  101.     FindClose();
  102.     CL_FNAME::Initialize(CL_INIT_CLASS_VARS);
  103.     if (fDestroyAll)                            // Destroy parent.
  104.         CL_FNAME_PARENT::Destroy(fDestroyAll);                    
  105.     return TRUE;
  106. }
  107.  
  108.  
  109. //----------------------------------------------------------------------------
  110. //   Description:    
  111. //    Parameters:
  112. //       Returns:    TRUE if successful.
  113. //----------------------------------------------------------------------------
  114. BOOL FN_M CL_FNAME::FindClose()
  115. {
  116.     if (pv)
  117.         {
  118.         FinfoFindClose(pv);
  119.         pv = NULL;
  120.         }
  121.     return TRUE;
  122. }
  123.  
  124.  
  125. //----------------------------------------------------------------------------
  126. //   Description:    
  127. //    Parameters:
  128. //       Returns:    TRUE if successful.
  129. //----------------------------------------------------------------------------
  130. BOOL FN_M CL_FNAME::FindFirst(PBS_FINFO pbs_finfo, USHORT usAttr)
  131. {
  132.     FindClose();
  133.  
  134.     BS_FINFO bs_finfo;
  135.     pv = FinfoFindFirst(pszBuf, usAttr, &bs_finfo);
  136.     if (pv == NULL)
  137.         return FALSE;
  138.  
  139.     CL_STRING::Copy(bs_finfo.szFname);
  140.     if (pbs_finfo)
  141.         *pbs_finfo = bs_finfo;
  142.     return TRUE;
  143. }
  144.  
  145.  
  146. //----------------------------------------------------------------------------
  147. //   Description:
  148. //    Parameters:
  149. //       Returns:    TRUE if successful.
  150. //----------------------------------------------------------------------------
  151. BOOL FN_M CL_FNAME::FindNext(PBS_FINFO pbs_finfo)
  152. {
  153.     if (pv == NULL)
  154.         return Error("Invalid find-next operation.");
  155.  
  156.     BS_FINFO bs_finfo;
  157.     if (!FinfoFindNext(pv, &bs_finfo))
  158.         {
  159.         FindClose();
  160.         return FALSE;
  161.         }
  162.  
  163.     CL_STRING::Copy(bs_finfo.szFname);
  164.     if (pbs_finfo)
  165.         *pbs_finfo = bs_finfo;
  166.     return TRUE;
  167. }
  168.  
  169.  
  170. //----------------------------------------------------------------------------
  171. //   Description:    Initialize object. 
  172. //                          Normally called by constructor.
  173. //                        Should allow multiple calls from various classes.
  174. //    Parameters:    sInit        Initialization code. May be one of the following:
  175. //                                        CL_INIT_CLASS            Reset class variables and
  176. //                                                                    and dynamic allocations for
  177. //                                                                    this class only.
  178. //                                        CL_INIT_CLASS_VARS    Reset class variables for
  179. //                                                                    this class only.
  180. //                                        CL_INIT_VARS            Reset class variables for
  181. //                                                                    this class only.
  182. //                                        CL_INIT_ALL                Initialize class and all 
  183. //                                                                    parent class, including
  184. //                                                                    dynamic memory allocation.
  185. //                                    Default is CL_INIT_ALL
  186. //       Returns:    TRUE if successful.
  187. //----------------------------------------------------------------------------
  188. BOOL FN_M CL_FNAME::Initialize(SHORT sInit)
  189. {
  190.     if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
  191.         CL_FNAME_PARENT::Initialize(sInit);
  192.  
  193.     pv = NULL;
  194.     return TRUE;
  195. }
  196.  
  197.  
  198. //----------------------------------------------------------------------------
  199. //   Description:    Assignment operator
  200. //                          NOTE: Don't copy object into self
  201. //    Parameters:    rccl_fname        Reference to right value.
  202. //       Returns:    Reference to new object.
  203. //----------------------------------------------------------------------------
  204. RCCL_FNAME FN_M CL_FNAME::operator=(RCCL_FNAME rccl_fname)
  205. {
  206.     if (this != &rccl_fname)
  207.         {
  208.         if (rccl_fname.IsError())
  209.             {
  210.             Destroy();
  211.             SetError(rccl_fname.ErrorCode());
  212.             }
  213.         else
  214.             {
  215.             CAST(CL_FNAME_PARENT,*this) = CAST(CL_FNAME_PARENT,rccl_fname);
  216.             }
  217.         }
  218.     return (RCCL_FNAME)*this;
  219. }
  220.  
  221.  
  222. //----------------------------------------------------------------------------
  223. //   Description:    Retrieve object from persistent storage
  224. //    Parameters:    pcsz        Name of object.
  225. //                        pcszSub    Sub-name of object.
  226. //                                    The first character of the name should be '~'.
  227. //                                    If NULL, no sub name is available.
  228. //                                    Default is NULL
  229. //       Returns:    TRUE if successful.
  230. //----------------------------------------------------------------------------
  231. BOOL FN_M CL_FNAME::Retrieve(PCSZ pcsz, PCSZ pcszSub)
  232. {
  233.     Assert(pcsz);
  234.                                                     // Create sub-name for object
  235.     CL_STRING string("%s~CL_FNAME", (pcszSub ? pcszSub: ""));
  236.     if (string.IsError())
  237.         return FALSE;
  238.                                                     // Get parent
  239.     if (!CL_FNAME_PARENT::Retrieve(pcsz, (PCSZ)string))
  240.         return FALSE;
  241.  
  242.     return !IsError();
  243. }
  244.  
  245.  
  246. //----------------------------------------------------------------------------
  247. //   Description:    Store object to persistent storage
  248. //    Parameters:    pcsz        Name of object.
  249. //                        pcszSub    Sub-name of object.
  250. //                                    The first character of the name should be '~'.
  251. //                                    If NULL, no sub name is available.
  252. //                                    Default is NULL
  253. //       Returns:    TRUE if successful.
  254. //----------------------------------------------------------------------------
  255. BOOL FN_M CL_FNAME::Store(PCSZ pcsz, PCSZ pcszSub)
  256. {
  257.     Assert(pcsz);
  258.     if (IsError())                                // Check that object is valid
  259.         return FALSE;
  260.                                                     // Create sub-name for object
  261.     CL_STRING string("%s~CL_FNAME", (pcszSub ? pcszSub: ""));
  262.     if (string.IsError())
  263.         return FALSE;
  264.                                                     // Store parent
  265.     if (!CL_FNAME_PARENT::Store(pcsz, (PCSZ)string))
  266.         return FALSE;
  267.  
  268.     return TRUE;                                // Done
  269. }
  270.  
  271.  
  272. //----------------------------------------------------------------------------
  273. //   Description:    Print object value to debugging output.
  274. //    Parameters:    pccl_fname        Pointer to dynamic object. 
  275. //                                    If NULL, static data elements are printed.
  276. //                                    Default is NULL.
  277. //                        pcsz        Name of object.
  278. //                                    If NULL, no name is displayed.
  279. //                                    Default is NULL.
  280. //                        cLevel    Display level. 
  281. //                                    Default is zero.
  282. //       Returns:
  283. //----------------------------------------------------------------------------
  284. #if COMPILE_DEBUG
  285. VOID FN_M CL_FNAME::Print(PCCL_FNAME pccl_fname, PCSZ pcsz, SIZET cLevel)
  286. {
  287. #if COMPILE_TEST
  288.     OutputL(cLevel, "CL_FNAME%s%s", (pcsz?"::":""), (pcsz?pcsz:""));
  289.     cLevel++;
  290.     if (pccl_fname)
  291.         {
  292.         Output(" <%p>\n", pccl_fname);
  293.         if(!pccl_fname->IsError())
  294.             {
  295. //            OutputL(cLevel, " = %d\n", pccl_fname->);
  296.             }
  297.         }
  298.     else
  299.         Output(" <NULL>\n");
  300.     CL_FNAME_PARENT::Print((CL_FNAME_PARENT _FAR_ *)pccl_fname, pcsz, cLevel);
  301.     return ;
  302. #else
  303.     NOTUSED(cLevel);
  304.     NOTUSED(pccl_fname);
  305.     NOTUSED(pcsz);
  306.     return ;
  307. #endif
  308. }
  309. #endif
  310.  
  311.  
  312. //----------------------------------------------------------------------------
  313. //   Description:    Run standard test suite on object.
  314. //    Parameters:    sTest        Test to run.
  315. //                                    If 0, run default tests.
  316. //                                    Default is 0.
  317. //       Returns:    TRUE if successful.
  318. //----------------------------------------------------------------------------
  319. #if COMPILE_DEBUG
  320. BOOL FN_M CL_FNAME::Test(SHORT sTest)
  321. {
  322. #if COMPILE_TEST
  323.     if (sTest == 1)                            // Test 1 is always a test of storage
  324.         {
  325.         CL_FNAME cl_fname;
  326.         cl_fname = "c:\\config.sys";
  327.         cl_fname.Store("CL_FNAME");
  328.         cl_fname.Retrieve("CL_FNAME");
  329.         CL_FNAME::Print(&cl_fname);
  330.         }
  331.  
  332.     CL_FNAME fname1 = "c:\\config.sys";
  333.     Print(&fname1);
  334.  
  335.     CL_FNAME fname2("c:\\%s", "config.sys");
  336.     Print(&fname2);
  337.     Output("Name = [%s]\n", (PCSZ)fname2);
  338.  
  339.     CL_FNAME fname3;
  340.     fname3("c:\\%s", "config.sys");
  341.     Print(&fname3);
  342.  
  343.     fname3 = "*.*";
  344.     if (fname3.FindFirst())
  345.         {
  346.         do
  347.             {
  348.             Print(&fname3);
  349.             }
  350.         while (fname3.FindNext());
  351.         }
  352.     return TRUE;
  353. #else
  354.     NOTUSED(sTest);
  355.     return TRUE;
  356. #endif
  357. }
  358. #endif
  359. //----------------------------------------------------------------------------
  360. //------------------------------- End of File --------------------------------
  361. //----------------------------------------------------------------------------
  362.